package com.finger.crowd.mvc.controller;

import com.finger.crowd.entity.Admin;
import com.finger.crowd.service.api.AdminService;
import com.finger.crowd.util.CrowdUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TestContrller {

    private static Logger logger = LoggerFactory.getLogger(TestContrller.class);
    @Autowired
    private AdminService adminService;

    @RequestMapping("/TestController.html")
    public String test(Model model, HttpServletRequest request) {
        boolean b = CrowdUtils.judgeRequestType(request);
        logger.info(String.valueOf(b));
        System.out.println(10 / 0);
        List<Admin> allAdmin = adminService.getAllAdmin();
        model.addAttribute("adminList", allAdmin);
        return "target";
    }

    @RequestMapping("/TestAjax.html")
    @ResponseBody
    public String ajax(@RequestParam("array[]") List<Integer> list) {

        for (Object o : list) {
            System.out.println(o);
        }
        return "target";
    }

    @RequestMapping("/TestAjax2.html")
    @ResponseBody
    public String ajax2Test(@RequestBody List<Integer> list) {
        for (Integer integer : list) {
            logger.info(String.valueOf(integer));
        }
        return "target";
    }

}
